import pygame as pg
import math
import random
import Statuses
import sys,os
def resource_path(relative_path):
    if getattr(sys, 'frozen', False):
        base_path = sys._MEIPASS
    else:
        base_path = os.path.abspath(".")
        # base_path = os.path.dirname(os.path.abspath(__file__))
    return os.path.join(base_path, relative_path)
class Pea():
    def __init__(self,player,angle = 0,ATK = 20):
        self.img = pg.image.load(resource_path("images/plants/ProjectilePea.png"))
        self.x = player.x
        self.y = player.y
        self.speed = 3
        self.ATK = ATK
        self.angle = angle
        self.rect = (self.x,self.y,self.img.get_width(),self.img.get_height())

    def __contains__(self,item):
        pass

    #子弹击中检测
    def hit(self,**kwargs):
        global Zombies,Peas
        Zombies = kwargs["Zombies"]
        for e in Zombies:
            if(self.x+20 >=e.x>=self.x-20 and self.y-40<=e.y <=self.y+40):
                
                e.healthy -= self.ATK
                e.healthyOnChange()
                return True
        return False
    
    def move(self):
        self.x += self.speed * math.cos(self.angle)
        self.y += self.speed * math.sin(self.angle)


class sinPea(Pea):
    def __init__(self, player):
        super().__init__(player)
        self.img = pg.image.load(resource_path("images/plants/ProjectilePea2.png"))

    def move(self):
        self.x += self.speed
        self.y += self.speed * math.sin(math.radians(self.x))*1.2 * 1.5


class bombPea(Pea):
    def __init__(self, player, angle=0):
        super().__init__(player, angle)
        self.img = pg.image.load(resource_path("images/plants/ProjectilePea3.png"))
        self.ATK = 100
        self.sonPea = Pea

    def hit(self,**kwargs):
        global Zombies,Peas
        Zombies = kwargs["Zombies"]
        Peas = kwargs["Peas"]
        for e in Zombies:
            if(self.x+20 >= e.x >= self.x-20 and self.y-40 <= e.y <= self.y+40):
                for i in range(10):
                    Peas.append(Pea(self,i * 36))
                e.healthy -= self.ATK
                e.healthyOnChange()
                return True
        return False
    
class poisonousPea(Pea):
    def hit(self,**kwargs):
        global Zombies,Peas
        Zombies = kwargs["Zombies"]
        for e in Zombies:
            if(self.x+20 >=e.x>=self.x-20 and self.y-40<=e.y <=self.y+40):
                e.healthy -=self.ATK
                e.healthyOnChange()
                e.statuses['poisoning'] = Statuses.poisoning(e,7)
                return True
        return False


class sinBombPea(sinPea,bombPea):
    def __init__(self, player):
        super().__init__(player)
